import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import 'log.dart';

abstract class BaseController {
  late final WidgetRef ref;
  late final appLifecycleListener = AppLifecycleListener(
      onHide: onHide,
      onResume: onResume,
      onStateChange: (state) {
        Log.e(state);
      });

  bool isActive = true;

  dynamic arguments;

  void onInit() {
    Log.i('生命周期 --> onInit -->$this');
  }

  void onBuild(BuildContext context) {
    Log.i('生命周期 --> onBuild -->$this');
  }

  void onHide() {
    Log.i('生命周期 --> onHide -->$this');
    isActive = false;
  }

  void onResume() {
    Log.i('生命周期 --> onResume -->$this');
    isActive = true;
  }

  void onDispose() {
    Log.i('生命周期 --> onDispose -->$this');
    isActive = false;
    // appLifecycleListener.dispose();
  }

  void onDestroy() {
    Log.i('生命周期 --> onDestroy -->$this');
    isActive = false;
  }

  BuildContext get context => ref.context;
}
